home *** CD-ROM | disk | FTP | other *** search
/ Pascal Super Library / Pascal Super Library (CW International)(1997).bin / LIBRARY / PCTV3N5 / STATUS.ZIP / STATDEMO.CPP < prev    next >
C/C++ Source or Header  |  1992-08-28  |  2KB  |  89 lines

  1. // Status bar demonstration by Tom Swan
  2.  
  3. #include <owl.h>
  4. #include "status.h"
  5. #include "statdemo.rch"
  6.  
  7. // The application class
  8. class TStatusApp: public TApplication {
  9. public:
  10.   TStatusApp(LPSTR AName, HINSTANCE AnInstance,
  11.     HINSTANCE APrevInstance, LPSTR ACmdLine, int ACmdShow)
  12.     : TApplication(AName, AnInstance, APrevInstance,
  13.       ACmdLine, ACmdShow) {};
  14.   virtual void InitMainWindow();
  15. };
  16.  
  17. // Main window class
  18. class TStatusWin: public TWindow {
  19.   PTStatusBar pStatusBar;
  20. public:
  21.   TStatusWin(PTWindowsObject AParent, LPSTR ATitle);
  22.   virtual BOOL CanClose();
  23.   virtual void CMFileExit(RTMessage)
  24.     = [CM_FIRST + CM_FILE_EXIT];
  25.   virtual void WMSize(RTMessage)
  26.     = [WM_FIRST + WM_SIZE];
  27.   virtual void WMMenuSelect(RTMessage)
  28.     = [WM_FIRST + WM_MENUSELECT];
  29. };
  30.  
  31. // Initialize TStatusApp's main window
  32. void TStatusApp::InitMainWindow()
  33. {
  34.   MainWindow = new TStatusWin(NULL, "Status Bar Demonstration");
  35. }
  36.  
  37. // Construct main window object
  38. TStatusWin::TStatusWin(PTWindowsObject AParent, LPSTR ATitle)
  39.   : TWindow(AParent, ATitle)
  40. {
  41.   AssignMenu(ID_MENU);
  42.   Attr.X = GetSystemMetrics(SM_CXSCREEN) / 8;
  43.   Attr.Y = GetSystemMetrics(SM_CYSCREEN) / 8;
  44.   Attr.H = Attr.Y * 6;
  45.   Attr.W = Attr.X * 6;
  46.   pStatusBar = new TStatusBar(this);
  47.   if (pStatusBar == NULL)
  48.     Status = EM_INVALIDCHILD;
  49. }
  50.  
  51. // Return TRUE if window can be closed
  52. BOOL TStatusWin::CanClose()
  53. {
  54.   pStatusBar->DisplayString(999);  // On-line help message
  55.   int result = MessageBox(HWindow, "End program?", "StatDemo",
  56.     MB_ICONQUESTION | MB_YESNO) == IDYES;
  57.   pStatusBar->DisplayString(0);    // Erase the message
  58.   return result;
  59. }
  60.  
  61. // Respond to File|Exit command; exit program
  62. void TStatusWin::CMFileExit(RTMessage)
  63. {
  64.   CloseWindow();
  65. }
  66.  
  67. // Resizing parent window; update child window
  68. void TStatusWin::WMSize(RTMessage msg)
  69. {
  70.   TWindow::WMSize(msg);
  71.   pStatusBar->AdjustSize(msg.LP.Lo, msg.LP.Hi);
  72. }
  73.  
  74. // Notate menu selections by passing message to child window
  75. void TStatusWin::WMMenuSelect(RTMessage msg)
  76. {
  77.   SendMessage(pStatusBar->HWindow, WM_MENUSELECT,
  78.     msg.WParam, msg.LParam);  
  79. }
  80.  
  81. int PASCAL WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  82.   LPSTR lpszCmdLine, int nCmdShow)
  83. {
  84.   TStatusApp StatusApp("StatusApp", hInstance, hPrevInstance,
  85.     lpszCmdLine, nCmdShow);
  86.   StatusApp.Run();
  87.   return StatusApp.Status;
  88. }
  89.